package com.pangu.web.module;

import java.util.HashMap;
import java.util.Map;

import org.nutz.ioc.annotation.InjectName;
import org.nutz.mvc.View;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Fail;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.Param;
import org.nutz.mvc.view.UTF8JsonView;
import org.nutz.mvc.view.ViewWrapper;

@InjectName("shopModule")
public class ShopModule {

	@At("/shop/*")
	@Ok("json")
	@Fail("http:404")
//	@Fail("jsp:jsp.noshop")
	public Map<String, Object> getShop(String shopName, int shopId) {
//		return String.format("{name:\"%s\", id:%d}", shopName, shopId);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("name", shopName);
		map.put("id", shopId);
		return map;
	}
	
	@At("/test")
	public View test(@Param("type") int type) {
		if (type == 0)
			return new ViewWrapper(new UTF8JsonView(null), "It is zero");
		else
			return new ViewWrapper(new UTF8JsonView(null), "It is not zero");
	}
}
